package com.td.module.system.dal.mysql.growth;

import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.system.controller.admin.growth.vo.type.GrowthModuleTypeExportReqVO;
import com.td.module.system.controller.admin.growth.vo.type.GrowthModuleTypePageReqVO;
import com.td.module.system.dal.dataobject.growth.GrowthModuleTypeAndListDO;
import com.td.module.system.dal.dataobject.growth.GrowthModuleTypeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 生长模型字典 Mapper
 *
 * @author wangxx
 */
@Mapper
public interface GrowthModuleTypeMapper extends BaseMapperX<GrowthModuleTypeDO> {

    default PageResult<GrowthModuleTypeDO> selectPage(GrowthModuleTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GrowthModuleTypeDO>()
                .likeIfPresent(GrowthModuleTypeDO::getName, reqVO.getName())
                .likeIfPresent(GrowthModuleTypeDO::getType, reqVO.getType())
                .eqIfPresent(GrowthModuleTypeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(GrowthModuleTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(GrowthModuleTypeDO::getId));
    }

    default List<GrowthModuleTypeDO> selectList(GrowthModuleTypeExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<GrowthModuleTypeDO>()
                .likeIfPresent(GrowthModuleTypeDO::getName, reqVO.getName())
                .likeIfPresent(GrowthModuleTypeDO::getType, reqVO.getType())
                .eqIfPresent(GrowthModuleTypeDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(GrowthModuleTypeDO::getCreateTime, reqVO.getCreateTime()));
    }

    default GrowthModuleTypeDO selectByName(String name) {
        return selectOne(GrowthModuleTypeDO::getName, name);
    }

    @Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
    List<GrowthModuleTypeAndListDO> selectGrowthModuleTypeAndList();
    GrowthModuleTypeAndListDO getGrowthModuleTypeAndList(@Param("id") Long id);
}
